<?php
/**
 * Holds class Image_GetFactory
 *
 * @author daantimmer
 *
 * @package Library
 * @subpackage Image
 */

/**
 * A simple callback class used to interface with a Image_Image.
 *
 * This callback factory returns a single color, defined by a pixel's location
 *
 * @author daantimmer
 */
class Image_GetFactory{

	/**
	 * @var string
	 */
	private $callback;

	/**
	 * Constructor
	 *
	 * @param string $callback callback to be called when calling $this->get()
	 * @return void
	 */
	public function __construct($callback){
		$callback = "get{$callback}";
		if(method_exists($this,$callback))
		$this->callback = $callback;
		else	throw new Excpetion("callback ({$callback}) not found");
	}

	/**
	 * Calls $callback();
	 *
	 * @param integer $x
	 * @param integer $y
	 * @param Image_Image $img
	 * @return Image_Lib_Color
	 */
	public function get($x,$y, Image_Image $img){
		return $this->{$this->callback}($x,$y,$img);
	}

	private function getRGB($x,$y, Image_Image $img){
		return $img->getColorRGB($x,$y);
	}

	private function getHSV($x,$y, Image_Image $img){
		return $img->getColorHSV($x,$y);
	}

	private function getH($x,$y, Image_Image $img){
		return $img->getColorH($x,$y);
	}

	private function getS($x,$y, Image_Image $img){
		return $img->getColorS($x,$y);
	}

	private function getV($x,$y, Image_Image $img){
		return $img->getColorV($x,$y);
	}
}